package rs.crawlerUtil;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;

public class HttpProxy extends Proxy {
	
	int weight;
	
	String hostName;
	
	int port;

	public HttpProxy(Type type, SocketAddress sa) {
		super(type, sa);
	}
	
	public int getWeight() {
		return weight;
	}
	

	public void setWeight(int weight) {
		this.weight = weight;
	}
	
	public String getHostName() {
		return hostName;
	}

	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}
	
	public String toString(){
		return hostName + ":" + port;
		
	}

	public static HttpProxy from(String address){
		String[] hostPort = address.split(":");
		String host = hostPort[0].replace("http://", "");
		int port = Integer.valueOf(hostPort[1]);
		return from(host, port);
	}

	public static HttpProxy from(String host, int port) {
		HttpProxy proxy = new HttpProxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
		proxy.setHostName(host);
		proxy.setPort(port);
		return proxy;
	}
	

}
